//
//  MyController.m
//  i5db
//
//  Created by iMuse on 15-5-11.
//  Copyright (c) 2015年 mySelf. All rights reserved.
//

#import "MyController.h"
#import "AppCenter.h"
#import "APPView.h"
#import "MyInfoController.h"
#import "MyAccountController.h"
#import "MyCooperController.h"
#import "MyTogetherController.h"
#import "MyActivityController.h"
#import "SettingController.h"

#define left 0
#define right 0
#define space 15

@interface MyController ()<tapViewDelegate>
{
    UIButton      * infoView;
    UIImageView * imageView;
    UILabel     * nameLabel;
    UILabel     * companyLabel;
   
}

@end

@implementation MyController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = @"我";
    }
    return self;
}
-(void) initSearchBar
{
    [super initSearchBar];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view setNeedsUpdateConstraints];
    [self initSearchBar];
    [self initView];
    
}
-(void)updateViewConstraints
{
    [super updateViewConstraints];
    [infoView autoPinToTopLayoutGuideOfViewController:self withInset:10];
    [infoView autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:left];
    [infoView autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:right];
    [infoView autoSetDimension:ALDimensionHeight toSize:60];
    
    [imageView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:5];
    [imageView autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:10];
    [imageView autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:5];
    [imageView autoSetDimension:ALDimensionWidth toSize:50];
    
    [nameLabel autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:0];
    [nameLabel autoPinEdge:ALEdgeLeft toEdge:ALEdgeRight ofView:imageView withOffset:10];
    [nameLabel autoSetDimension:ALDimensionWidth toSize:120];
    [nameLabel autoSetDimension:ALDimensionHeight toSize:40];
    
    [companyLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:nameLabel withOffset:-5];
    [companyLabel autoPinEdge:ALEdgeLeft toEdge:ALEdgeRight ofView:imageView withOffset:10];
    [companyLabel autoSetDimension:ALDimensionHeight toSize:10];
    [companyLabel autoSetDimension:ALDimensionWidth toSize:200];
    
}


-(void) initView
{
    infoView = [UIButton newAutoLayoutView];
    [infoView addTarget:self action:@selector(myInfoClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [infoView setBackgroundColor:[UIColor whiteColor]];
    [self.view addSubview:infoView];
    
    imageView = [UIImageView newAutoLayoutView];
    imageView.image = [UIImage imageNamed:@"NoHeaderImge"];
    [infoView addSubview:imageView];
    
    nameLabel = [UILabel newAutoLayoutView];

    nameLabel.font = [UIFont systemFontOfSize:13];
    nameLabel.text = @"董家祎";
    nameLabel.textColor = [UIColor blackColor];
    [infoView addSubview:nameLabel];
    
    companyLabel = [UILabel newAutoLayoutView];

    companyLabel.font = [UIFont systemFontOfSize:10];
    companyLabel.textColor = [AppCenter color:@"164,164,164,1"];
    companyLabel.text = @"北京明智有限公司";
    [infoView addSubview:companyLabel];
    
    
    
    
    APPView * AccountView = [APPView newAutoLayoutView];
    AccountView.backgroundColor = [UIColor whiteColor];
    AccountView.tag = 1;
    AccountView.delagate = self;
    [self.view addSubview:AccountView];
    [AccountView setLaeblText:@"账户"];
    [AccountView setImageView:[UIImage imageNamed:@"MoreMyBankCard.png"]];
    [AccountView setLineHiddent];
    [AccountView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:infoView withOffset:space];
    [AccountView autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:left];
    [AccountView autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:right];
    [AccountView autoSetDimension:ALDimensionHeight toSize:40];
    
    UILabel * jifenLabel = [UILabel newAutoLayoutView];
    jifenLabel.text = @"2000";
    jifenLabel.textColor = [AppCenter color:@"76,187,248,1"];
    jifenLabel.font   = [UIFont systemFontOfSize:10];
    [AccountView addSubview:jifenLabel];
    [jifenLabel autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:0];
    [jifenLabel autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:0];
    [jifenLabel autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:20];
    
    
    APPView * cooperView = [APPView newAutoLayoutView];
    cooperView.backgroundColor = [UIColor whiteColor];
    cooperView.delagate = self;
    cooperView.tag = 2;
    
    [self.view addSubview:cooperView];
    [cooperView setLaeblText:@"合作"];
    [cooperView setImageView:[UIImage imageNamed:@"hezuoIco.png"]];
    
    [cooperView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:AccountView withOffset:space];
    [cooperView autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:left];
    [cooperView autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:right];
    [cooperView autoSetDimension:ALDimensionHeight toSize:40];
    
    
    APPView * togetherView = [APPView newAutoLayoutView];
    togetherView.backgroundColor = [UIColor whiteColor];
    togetherView.delagate = self;
    togetherView.tag = 3;
    
    [self.view addSubview:togetherView];
    [togetherView setLaeblText:@"聚会"];
    [togetherView setImageView:[UIImage imageNamed:@"ne_nearbygroup_icon.png"]];
    [togetherView setLineHiddent];
    [togetherView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:cooperView withOffset:0];
    [togetherView autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:left];
    [togetherView autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:right];
    [togetherView autoSetDimension:ALDimensionHeight toSize:40];
    
    APPView * settingView = [APPView newAutoLayoutView];
    settingView.backgroundColor = [UIColor whiteColor];
    settingView.delagate = self;
    settingView.tag = 4;
    
    [self.view addSubview:settingView];
    [settingView setLaeblText:@"设置"];
    [settingView setImageView:[UIImage imageNamed:@"MoreSetting.png"]];
    [settingView setLineHiddent];
    [settingView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:togetherView withOffset:space];
    [settingView autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:left];
    [settingView autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:right];
    [settingView autoSetDimension:ALDimensionHeight toSize:40];
    
    
}
-(void)myInfoClick:(id)sender
{
    MyInfoController * infoController = [[MyInfoController alloc] init];
    [self.navigationController pushViewController:infoController animated:YES];
}
-(void)onTapAppImage:(NSString *)_tag
{
    NSInteger tag = [_tag intValue];
    if (tag ==1)
    {
        MyAccountController* controller = [[MyAccountController alloc] init];
        [self.navigationController pushViewController:controller animated:YES];
    }else if (tag==2)
    {
        MyCooperController* cooController = [[MyCooperController alloc] init];
        [self.navigationController pushViewController:cooController animated:YES];
    }else if(tag ==3)
    {
        MyActivityController * controller = [[MyActivityController alloc] init];
        [self.navigationController pushViewController:controller animated:YES];
      
    }else if (tag ==4)
    {
        SettingController* controller =[[SettingController alloc] init];
        [self.navigationController pushViewController:controller animated:YES];
    }
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
 
}



@end
